ActiveReports 10 Server User Guide
Get a Security Token
ActiveReports 10 Server User Guide > How To > Get a Security Token

When you use the HTML5 Viewer to access the ActiveReports Server web site, you need to provide the Report Service with a security token to use.

Below are the steps to retrieve a security token.

To get a security token by the Javascript function

  1. In the target HTML page, add the following code to get a security token. The code might vary depending on the technology that you use to develop the HTML5 Viewer component. For more information, see the HTML5 Viewer Sample. By default, this sample is in the following folder.

    C:\ActiveReports 10 Server\SDK\Samples\HTML5 Viewer.

    Note: You need to change these settings in the code below.

    • url parameter represents the location (reportservice.svc/json/login) which stays constant where as the arsEndpoint represents the URL used to access the Report Portal Website. Example: http://<ActiveReports10ServerName>:<portnumber>.
    • username is your username to log into the ActiveReports Server web site.
    • password is your password to log into the ActiveReports Server web site.
    Javascript
    Copy Code
    function getSecurityToken() {
        if (_securityToken) return _securityToken;
        _securityToken = "error";
    
        try {
            $.ajax({
                 async: false,
                 type: "POST",
                 url: arsEndpoint + "ReportService.svc/json/Login",
                 data: JSON.stringify({
                       username: "username",
                       password: "password"
                 }),
                 contentType: "application/json",
                 dataType: "json"
            }).done(function(res) {
                  _securityToken = res.d;
            }).fail(function() {
                  _securityToken = "error";
            });
        } catch(e) {
              return "error";
        }
    
        return _securityToken;
    }
    

    If you are using the REST API, add the following code to get a security token. 

    Javascript
    Copy Code
    function getSecurityToken() {
        if (_securityToken) return _securityToken;
        _securityToken = "error";
    
        try {
            $.ajax({
                 async: false,
                 type: "POST",
                 url: arsEndpoint + "api/accounts/login",
                 headers: JSON.stringify({
                       user: "username",
                       password: "password"
                 }),
                 contentType: "application/json",
                 dataType: "json"
            }).done(function(res) {
                  _securityToken = res.Token;
            }).fail(function() {
                  _securityToken = "error";
            });
        } catch(e) {
              return "error";
        }
    
        return _securityToken;
    }
    
See Also

SDK Tutorials